package com.oocl.controller;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.oocl.dataprocessImpl.DataProcessImpl;
import com.oocl.modle.Customer;
import com.oocl.modle.Message;
import com.oocl.network.NetworkOperat;
import com.oocl.parseMessage.IParseMessage;
import com.oocl.parseMessageImpl.ParseMessage;
import com.oocl.printFormat.PrintFormat;
import com.oocl.util.Valid;
import com.oocl.util.ipml.FileLoader;
import com.oocl.util.ipml.Validtor;

public class Controller {
	
	Message[] messages;
	PrintFormat pf;
	Valid validtor;
	Customer[] customers;
	DataProcessImpl dpl;
	IParseMessage ipm;
	NetworkOperat network;
	
	
	
	public Controller() {
		pf = new PrintFormat();
		validtor = new Validtor();
		dpl = new DataProcessImpl();
		ipm = new ParseMessage(new Validtor());
		network = new NetworkOperat();
	}

	public void operat() throws Exception{
		loadFile();
		customers = ipm.parse(messages);
		dpl.saveCustomer(customers);
		pf.printByBirth();
		pf.printById();
		pf.printXML();
		pf.complete();
		
		network.start();
	}

	public Message[] loadFile() throws IOException{
		messages = FileLoader.loadFile("data.txt");
		return messages;
	}
}
